<?php
//此文档为项目赛报名页
require_once("./bm_header.php");
$is_admin = isset($_SESSION['administrator']) || isset($_SESSION[$BM_ADMIN]);
global $TeamBool;
$ckind = 1;
if (isset($_GET['cid'])) 
{
    $cid = intval($_GET['cid']);
    require_once("./judgecid.php"); //判断查看权限、比赛id合法性等等非正常访问
    if($user_active1 == 'N')
    {
    	?>
    	
		<div class="content bolr">
		<style type="text/css">
		<!--
		.STYLE1 {color: #FF3300}
		-->
		</style>
		<h2 class="h2">您尚未获得注册软件作品大赛的权限。</h2>
      	<div class="middle">
          <table border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td height="30">&nbsp;</td>
              <td height="30" colspan="2" align="left"><span class="STYLE1">用户注册：点击页眉“【<strong><a href="<?php echo $BM_HOME."/registerpage.php";?>">注册教练帐号</a></strong>】”按要求认真填写信息后提交。</span></td>
            </tr>
            <tr>
              <td height="30">&nbsp;</td>
              <td height="30" colspan="2" align="left"><span class="STYLE1">用户激活：登录后点击页眉“【<strong><a href="<?php echo $BM_HOME."/userinfo.php";?>">查看帐号信息</a></strong>】”，上传有相关单位公章的身份证明文件的清晰扫描或拍照附件（打包为RAR或ZIP格式上传），管理员会定期检查公文并激活用户。</span></td>
            </tr>
          </table>
         </div>
		<div style="height:150px;"></div>
		</div>
		<?php 
		require_once("./bm_footer.php");
        exit(0);
    }
	$sql    = "SELECT * FROM `cr_contest` WHERE `contest_id`='$cid' ";
	$result = mysql_query($sql);
	$row    = mysql_fetch_object($result);
	$now    = time();
	$start  = strtotime($row->contest_1_start);
	$end    = strtotime($row->contest_1_end);
	$view_description = $row->contest_1_description;
	$view_start = $view_start_time1;
	$view_end = $view_end_time1;
	mysql_free_result($result);
	
	$team_cid = $cid;	
    $user_id = $_SESSION['user_id'];
    //读教练信息
    $sql     = "SELECT * FROM `cr_user` WHERE `user_id`='$user_id' ";
    $result  = mysql_query($sql);
    $row     = mysql_fetch_object($result);
    $user_school  = $row->user_school;
    mysql_free_result($result);
	        
	        
    if (isset($_GET['func']))
    {
    /*******************_GET有func域为team***************************/
	    if($_GET['func'] == 'team') 
	    {
	        if ($now < $contest_1_start) 
	        {
	            echo "<script language='javascript'>\n";
	            echo "alert('注册尚未开始!');\n";
	            echo "history.go(-1);\n";
	            echo "</script>";
	            require_once("bm_footer.php");
	            exit(0);
	        }
	        if ($now > $contest_1_end) 
	        {
	            echo "<script language='javascript'>\n";
	            echo "alert('注册已结束!');\n";
	            echo "history.go(-1);\n";
	            echo "</script>";
	            require_once("bm_footer.php");
	            exit(0);
	        }
	
	        
	        
	        if (isset($_GET['tid'])) //如果GET到队伍编号team_id即tid，则是修改队伍，否则是增加队伍
	        {
	            global $TeamBool;
	            $TeamBool = true;
	            $team_id  = $_GET['tid'];
	            $sql      = "SELECT * FROM `cr_team` WHERE `team_id`='$team_id' AND `team_kind` !=0 AND `team_cid`='$cid'";
	            $result   = mysql_query($sql);
	            $rows_cnt = mysql_num_rows($result);
	            if ($rows_cnt == 0) 
	            {
	                echo "<script language='javascript'>\n";
	                echo "alert('没有这样一支队伍!');\n";
	                echo "history.go(-1);\n";
	                echo "</script>";
	                mysql_free_result($result);
	                exit(0);
	            }
	            $row = mysql_fetch_object($result);
	            if ($row->team_school != $user_school) //如果教练不是这个队伍的学校的（只有通过修改get的网址才会遇到这情况）
	            {
	                echo "<script language='javascript'>\n";
	                echo "alert('没有修改权限!');\n";
	                echo "history.go(-1);\n";
	                echo "</script>";
	                mysql_free_result($result);
	                exit(0);
	            }
	            $team_name   = SqlToHtml($row->team_name);
	            $team_school = SqlToHtml($row->team_school);
	            $team_coach  = SqlToHtml($row->team_coach); //这个不是注册这个team的user，而是注册填表的领队，一个教练注册的几个队伍可以有不同领队
	            $team_phone  = SqlToHtml($row->team_phone);
	            $team_kind   = SqlToHtml($row->team_kind);
	            $team_xmname = SqlToHtml($row->team_xmname);
	            mysql_free_result($result);
	        } 
	        else 
	        {
	            global $TeamBool;
	            $TeamBool = false;
	            $sql      = "SELECT * FROM `cr_team` WHERE `team_kind` != 0 AND `user_id`='$user_id' AND `team_cid`='$cid'";
	            $result   = mysql_query($sql);
	            $rows_cnt = mysql_num_rows($result);
	            if ($rows_cnt >= $XM_TEAM_LIMIT) 
	            {
	                echo "<script language='javascript'>\n";
	                echo "alert('已到达报名队数限制，不能增加队伍!');\n";
	                echo "window.location.href='" . $BM_HOME . "/xiangmu.php?cid=$cid';\n";
	                //echo "history.go(-1);\n";
	                echo "</script>";
	                exit(0);
	            }
	            
	        }
	        
	        if (isset($_POST['do'])) 
	        {
	            if ($now < $start || $now > $end) 
	            {
	                echo "<script language='javascript'>\n";
	                echo "alert('不在注册时间范围内，提交无效!');\n";
	                echo "history.go(-1);\n";
	                echo "</script>";
	                exit(0);
	            }
	            
	            $vcode = trim($_POST['vcode']);
	            if ($BM_VCODE && ($vcode != $_SESSION["vcode"] || $vcode == "" || $vcode == null)) {
	                echo "<script language='javascript'>\n";
	                echo "alert('验证码输入错误!');\n";
	                echo "history.go(-1);\n";
	                echo "</script>";
	                exit(0);
	            }
	            require_once("./include/check_post_key.php");
	            $team_name   = myMQpro($_POST['team_name']);
	            $team_xmname = myMQpro($_POST['team_xmname']);
	            //$team_school=myMQpro($_POST['team_name']);
	            $team_coach  = myMQpro($_POST['team_coach']);
	            $team_phone  = myMQpro($_POST['team_phone']);
	            $team_kind   = $_POST['team_kind'];
	            if ($TeamBool) //修改信息
	                {
	                //更新队伍信息
	                $sql = "UPDATE `cr_team` set `team_school`='$user_school', `team_name`='$team_name',`team_coach`='$team_coach' ,`team_phone`='$team_phone', `team_xmname`='$team_xmname', `team_kind`=$team_kind WHERE `team_id`=$team_id";
	                mysql_query($sql); // or die(mysql_error());
	            } else //增加信息
	                {
	                //插入队伍
	                $sql = "INSERT INTO `cr_team`(`team_name`,`team_school`,`team_cid`,`team_coach`,`team_phone`,`team_xmname`, `team_kind`, `user_id`)
		VALUES('$team_name','$user_school','$team_cid','$team_coach','$team_phone', '$team_xmname', $team_kind, '$user_id')"; //team_kind不为0，表示是项目竞赛的team，这个标记在查询的时候用
	                mysql_query($sql); // or die(mysql_error());
	                $team_id = mysql_insert_id();
	            }
	            
	            ?>
					<script language='javascript'>
					alert('提交成功!');
					window.location="<?php echo $BM_HOME."/xiangmu.php?cid=".$cid;?>";
					</script>";
				<?php 
	            header("Location: ./xiangmu.php?cid=" . $cid);
	        }
	        
	        
	        if ($TeamBool) 
	        {
	            $team_name   = SqlToHtml($team_name);
	            $team_xmname = SqlToHtml($team_xmname);
	            $team_school = SqlToHtml($team_school);
	            $team_coach  = SqlToHtml($team_coach);
	            for ($i = 0; $i < 3; $i++) 
	            {
	                $stu_card[$i]   = SqlToHtml($stu_card[$i]);
	                $stu_number[$i] = SqlToHtml($stu_number[$i]);
	                $stu_name[$i]   = SqlToHtml($stu_name[$i]);
	                $stu_major[$i]  = SqlToHtml($stu_major[$i]);
	                $stu_grade[$i]  = SqlToHtml($stu_grade[$i]);
	                $stu_sex[$i]    = SqlToHtml($stu_sex[$i]);
	                $stu_cloth[$i]  = SqlToHtml($stu_cloth[$i]);
	            }
	        }
	    	$xm_kind_array;
	        $sql = "SELECT `xmkind_name` FROM `cr_xmkind` WHERE `contest_id`=$cid ORDER BY `xmkind_num` ASC";
	        $result = mysql_query($sql) or die(mysql_error());
	        $kindnum = mysql_num_rows($result);
	        for ($i = 1; $i <= $kindnum; $i++) 
	        {
	            $row = mysql_fetch_row($result);
	            $xm_kind_array[$i] = $row[0];
	        }
	        mysql_free_result($result);
			require_once("template/".$BM_TEMPLATE."/xiangmu_team.php");
	    }
	    
	    
	    
    /*******************管理队员***************************/
	    else if($_GET['func'] == 'stu' || $_GET['func'] == 'stuinfo')
	    {
	    	
		    $team_id = $_GET['tid'];
		    $sql      = "SELECT * FROM `cr_team` WHERE `team_id`=$team_id AND `team_kind` != 0";
		    $result   = mysql_query($sql);
		    $rows_cnt = mysql_num_rows($result);
		    if ($rows_cnt == 0) 
		    {
		        echo "<script language='javascript'>\n";
		        echo "alert('队伍编号错误!');\n";
		        echo "history.go(-1);\n";
		        echo "</script>";
		        mysql_free_result($result);
		    	require_once("bm_footer.php");
		        exit(0);
		    }
		    $row = mysql_fetch_object($result);
		    if ($row->team_cid != $cid) 
		    {
		        echo "<script language='javascript'>\n";
		        echo "alert('队伍编号错误!');\n";
		        echo "history.go(-1);\n";
		        echo "</script>";
		        mysql_free_result($result);
		    	require_once("bm_footer.php");
		        exit(0);
		    }
		    $team_name   = $row->team_name;
		    $team_school = $row->team_school;
		    $team_cid    = $row->team_cid;
		    $team_coach  = $row->team_coach;
		    $team_phone  = $row->team_phone;
		    $team_upload = $row->team_upload;
		    
		    if ($user_school != $team_school) 
		    {
		        echo "<script language='javascript'>\n";
		        echo "alert('没有查看权限!');\n";
		        echo "history.go(-1);\n";
		        echo "</script>";
		        mysql_free_result($result);
		    	require_once("bm_footer.php");
		        exit(0);
		    }
		    mysql_free_result($result);
    /*******************队员信息增改，_GET有func域为stuinfo***************************/
		    if($_GET['func'] == 'stuinfo')
		    {
		        if ($now < $contest_1_start) 
		        {
		            echo "<script language='javascript'>\n";
		            echo "alert('注册尚未开始!');\n";
		            echo "history.go(-1);\n";
		            echo "</script>";
		    		require_once("bm_footer.php");
		            exit(0);
		        }
		        if ($now > $contest_1_end) {
		            echo "<script language='javascript'>\n";
		            echo "alert('注册已结束!');\n";
		            echo "history.go(-1);\n";
		            echo "</script>";
		    		require_once("bm_footer.php");
		            exit(0);
		        }
		        
		        $team_id = $_GET['tid'];
		        if (isset($_GET['sid'])) //如果GET到队员编号stu_id即sid，则是修改信息，否则是增加队员
		        {
		            global $StuBool;
		            $StuBool  = true;
		            $stu_id   = $_GET['sid'];
		            $sql      = "SELECT * FROM `cr_stu` WHERE `stu_id`='$stu_id'";
		            $result   = mysql_query($sql);
		            $rows_cnt = mysql_num_rows($result);
		            if ($rows_cnt == 0) 
		            {
		                echo "<script language='javascript'>\n";
		                echo "alert('没有这样一名队员!');\n";
		                echo "history.go(-1);\n";
		                echo "</script>";
		                mysql_free_result($result);
		    			require_once("bm_footer.php");
		                exit(0);
		            }
		            $row = mysql_fetch_object($result);
		            if ($row->stu_school != $user_school) //如果教练不是这个队员的学校的（只有通过修改get的网址才会遇到这情况）
		                {
		                echo "<script language='javascript'>\n";
		                echo "alert('没有修改权限!');\n";
		                echo "history.go(-1);\n";
		                echo "</script>";
		                mysql_free_result($result);
		    			require_once("bm_footer.php");
		                exit(0);
		            }
		            $stu_card   = SqlToHtml($row->stu_card);
		            $stu_number = SqlToHtml($row->stu_number);
		            $stu_name   = SqlToHtml($row->stu_name);
		            $stu_major  = SqlToHtml($row->stu_major);
		            $stu_grade  = SqlToHtml($row->stu_grade);
		            $stu_sex    = SqlToHtml($row->stu_sex);
		            $stu_cloth  = SqlToHtml($row->stu_cloth);
		        } 
				else //没有sid，是增加队员
		        {
		            global $StuBool;
		            $StuBool  = false;
		            $tid      = $_GET['tid'];
		            $sql      = "SELECT * FROM `cr_stu` WHERE `team_id` = '$team_id'";
		            $result   = mysql_query($sql);
		            $rows_cnt = mysql_num_rows($result);
		            if ($rows_cnt >= $XM_STU_LIMIT) 
		            {
		    			require_once("bm_footer.php");
		                echo "<script language='javascript'>\n";
		                echo "alert('一个项目参赛队至多由 $XM_STU_LIMIT 名队员组成!');\n";
		                echo "window.location.href='" . $BM_HOME . "/xiangmu.php?cid=$cid&tid=$tid&func=stu';\n";
		                //echo "history.go(-1);\n";
		                echo "</script>";
		                mysql_free_result($result);
		                exit(0);
		            }
		            
		        }
		        
		        if (isset($_POST['do'])) 
		        {
		            if ($now < $start || $now > $end) 
		            {
		    			require_once("bm_footer.php");
		                echo "<script language='javascript'>\n";
		                echo "alert('不在注册时间范围内，提交无效!');\n";
		                echo "history.go(-1);\n";
		                echo "</script>";
		                exit(0);
		            }
		            
		            require_once("./include/check_post_key.php");
		            
		            $vcode = trim($_POST['vcode']);
		            if ($BM_VCODE && ($vcode != $_SESSION["vcode"] || $vcode == "" || $vcode == null)) 
		            {
		    			require_once("bm_footer.php");
		                echo "<script language='javascript'>\n";
		                echo "alert('验证码输入错误!');\n";
		                echo "history.go(-1);\n";
		                echo "</script>";
		                exit(0);
		            }
		            require_once("./include/check_post_key.php");
		            
		            $stu_card   = myMQpro($_POST['stu_card']);
		            $stu_number = myMQpro($_POST['stu_number']);
		            $stu_name   = myMQpro($_POST['stu_name']);
		            $stu_school = myMQpro($user_school);
		            $stu_major  = myMQpro($_POST['stu_major']);
		            $stu_grade  = myMQpro($_POST['stu_grade']);
		            $stu_sex    = myMQpro($_POST['stu_sex']);
		            $stu_cloth  = myMQpro($_POST['stu_cloth']);
		            $sql        = "SELECT * FROM `cr_stu`, `cr_team` WHERE `cr_stu`.`stu_card`='$stu_card' AND `cr_stu`.`team_id`=`cr_team`.`team_id` AND `cr_team`.`team_cid`=$cid";
		            $result     = mysql_query($sql);
		            $rows_cnt   = mysql_num_rows($result);
		            if ($rows_cnt > 0 && (!$StuBool || $team_id != mysql_fetch_object($result)->team_id)) 
		            {
		                echo "<script language='javascript'>\n";
		                echo "alert('队员 ".$stu_name."(身份证号:".$stu_card.") 已注册其他比赛或在其他队中！同次赛事一名队员只能参加一项比赛的一支队伍。".$rows_cnt."');\n";
		                echo "window.location.href='" . $BM_HOME . "/xiangmu.php?cid=$cid&tid=$team_id&func=stu';\n";
		                //echo "history.go(-1);\n";
		                echo "</script>";
		                mysql_free_result($result);
		    			require_once("bm_footer.php");
		                exit(0);
		            }
		            
		            
		            if ($StuBool) //修改信息
		            {
		                $sql = "UPDATE `cr_stu` set `stu_card`='$stu_card',`stu_number`='$stu_number',`stu_name`='$stu_name',`stu_school`='$stu_school',`stu_major`='$stu_major',`stu_grade`='$stu_grade',`stu_sex`='$stu_sex',`stu_cloth`='$stu_cloth' WHERE `stu_id`='$stu_id'";
		                mysql_query($sql); // or die(mysql_error());
		            } 
					else //增加信息
		            {
		                $sql = "INSERT INTO `cr_stu`
		(`stu_card`, `stu_number`, `stu_name`, `stu_school`, `stu_major`, `stu_grade`, `stu_sex`, `stu_cloth`, `team_id`, `stu_123`) 
		VALUES
		('$stu_card','$stu_number','$stu_name','$stu_school','$stu_major','$stu_grade','$stu_sex','$stu_cloth','$team_id','5')";
		                mysql_query($sql); // or die(mysql_error());
		            }
		            ?>
						<script language='javascript'>
						alert('提交成功!');
						window.location="<?php echo $BM_HOME."/xiangmu.php?cid=$cid&tid=$team_id&func=stu";?>";
						</script>";
					<?php 
		            header("Location: ./xiangmu.php?cid=$cid&tid=$team_id&func=stu");
		        }
		        if ($StuBool) 
				{
		            $team_name   = SqlToHtml($team_name);
		            $team_school = SqlToHtml($team_school);
		            $team_coach  = SqlToHtml($team_coach);
		            for ($i = 0; $i < 3; $i++) 
					{
		                $stu_card   = SqlToHtml($stu_card);
		                $stu_number = SqlToHtml($stu_number);
		                $stu_name   = SqlToHtml($stu_name);
		                $stu_major  = SqlToHtml($stu_major);
		                $stu_grade  = SqlToHtml($stu_grade);
		                $stu_sex    = SqlToHtml($stu_sex);
		                $stu_cloth  = SqlToHtml($stu_cloth);
		            }
		        }
				require_once("template/".$BM_TEMPLATE."/xiangmu_stuinfo.php");
		    }
    /*******************队内队员列表，_GET有func域为stu***************************/
		    else
		    {
		        $sum_stu      = 0;
		        $sql    = "SELECT * FROM `cr_stu` WHERE `team_id`=$team_id";
		        $result = mysql_query($sql);
		        while ($row = mysql_fetch_object($result)) 
		        {
		        	$stu_id[$sum_stu] = SqlToHtml($row->stu_id);
		        	$stu_card[$sum_stu] = SqlToHtml($row->stu_card);
		        	$stu_number[$sum_stu] = SqlToHtml($row->stu_number);
		        	$stu_name[$sum_stu] = SqlToHtml($row->stu_name);
		        	$stu_major[$sum_stu] = SqlToHtml($row->stu_major);
		        	$stu_grade[$sum_stu] = SqlToHtml($row->stu_grade);
		        	$stu_sex[$sum_stu] = SqlToHtml($row->stu_sex);
		        	$stu_cloth[$sum_stu] = SqlToHtml($row->stu_cloth);
		        	$sum_stu ++;
		        }
				require_once("template/".$BM_TEMPLATE."/xiangmu_stulist.php");
		    }
	    }
    /*******************管理文档***************************/
	    else if($_GET['func'] == 'doc')
	    {
		    $team_id = $_GET['tid'];
			$sql      = "SELECT * FROM `cr_team` WHERE `team_id`='$team_id' AND `team_kind` != 0";
		    $result   = mysql_query($sql);
		    $rows_cnt = mysql_num_rows($result);
		    if ($rows_cnt == 0) 
		    {
		        echo "<script language='javascript'>\n";
		        echo "alert('队伍编号错误!');\n";
		        echo "history.go(-1);\n";
		        echo "</script>";
		        mysql_free_result($result);
		        exit(0);
		    }
		    $row = mysql_fetch_object($result);
		    if ($row->team_cid != $cid) {
		        echo "<script language='javascript'>\n";
		        echo "alert('队伍编号错误!');\n";
		        echo "history.go(-1);\n";
		        echo "</script>";
		        mysql_free_result($result);
		        exit(0);
		    }
		    $team_name   = SqlToHtml($row->team_name);
		    $team_school = SqlToHtml($row->team_school);
		    $team_cid    = SqlToHtml($row->team_cid);
		    $team_coach  = SqlToHtml($row->team_coach);
		    $team_phone  = SqlToHtml($row->team_phone);
		    $team_upload = SqlToHtml($row->team_upload);
		    
		    
		    if ($user_school != $team_school) {
		        echo "<script language='javascript'>\n";
		        echo "alert('没有查看权限!');\n";
		        echo "history.go(-1);\n";
		        echo "</script>";
		        mysql_free_result($result);
		        exit(0);
		    }
		    
		    mysql_free_result($result);
		    
		    $longmsg = "</br>";
		    if (isset($_POST['do'])) 
		    {
		        if ($now < $contest_1_start || $now > $contest_1_end) 
		        {
		            echo "<script language='javascript'>\n";
		            echo "alert('不在注册时间，不能修改或上传文档!');\n";
		            echo "history.go(-1);\n";
		            echo "</script>";
		            mysql_free_result($result);
		            exit(0);
		        }
		        $oldfile   = $_FILES['file']['name']; //获取文件上传之前的全名
		        $arr       = explode(".", $oldfile); //将文件以.为分隔转换为数组变量
		        $key       = count($arr) - 1; //获取数组就量的最后一个变量键
		        $flextends = $arr[$key]; //获取上传前的文件扩展名
		        $ext       = strtolower($flextends); //算出文件的扩展名并进行大小写转换
		        
		        if ($ext != "rar" && $ext != "zip") 
				{
		            $longmsg.=".$ext 文件不符合要求";
		        } 
				else if($_FILES["file"]["size"] > $XM_SIZE_LIMIT)
				{
					 $longmsg.="文档超出限制大小";
				}
				else if ((($_FILES["file"]["type"] == "application/octet-stream") || ($_FILES["file"]["type"] == "application/x-zip-compressed")) && ($_FILES["file"]["size"] < $XM_SIZE_LIMIT)) //限制文件上传格式和大小
		        {
		            if ($_FILES["file"]["error"] > 0) 
					{
		                $longmsg.="Return Code: " . $_FILES["file"]["error"] . "<br />";
		            } 
					else 
					{
		                $longmsg.="文件名: " . $_FILES["file"]["name"] . "<br />";
		                $longmsg.="文件格式: " . $_FILES["file"]["type"] . "<br />";
		                $longmsg.="文件大小: " . ($_FILES["file"]["size"] / 1024) . " KB<br />";
		                //    $longmsg.="缓存文件夹: " . $_FILES["file"]["tmp_name"];
		                $rar_zip;
		                if ($_FILES["file"]["type"] == "application/octet-stream") {
		                    $rar_zip                = "rar";
		                    $_FILES["file"]["name"] = $team_id . ".rar";
		                } else if ($_FILES["file"]["type"] == "application/x-zip-compressed") {
		                    $rar_zip                = "zip";
		                    $_FILES["file"]["name"] = $team_id . ".zip";
		                }
		                
		                
		                move_uploaded_file($_FILES["file"]["tmp_name"], $UPLOAD_ROUT . $_FILES["file"]["name"]);
		                $longmsg.="文件成功上传";
		                
		                $team_upload = myMQpro($DOWNLOAD_ROUT . "?file=" . $team_id . "&rz=" . $rar_zip);
		                $sql         = "UPDATE `cr_team` set `team_upload` = '$team_upload' WHERE `team_id`=$team_id";
		                mysql_query($sql); // or die(mysql_error());
		                
		            }
		        } 
				else 
				{
		            $longmsg.="文件不符合要求";
		        }
		    }
			require_once("template/".$BM_TEMPLATE."/xiangmu_doc.php");
	    }
    }
    /*******************查看队伍列表，即_GET没有func域***************************/
    else 
    {
        $user_id = $_SESSION['user_id'];
        
        //读教练信息
        $sql    = "SELECT * FROM `cr_user` WHERE `user_id`='$user_id' ";
        $result = mysql_query($sql);
        $row    = mysql_fetch_object($result);
        $user_school = $row->user_school;
        mysql_free_result($result);
        
        $sql    = "SELECT * FROM `cr_xmkind` WHERE `contest_id`= $cid ORDER BY xmkind_num ASC";
        $result = mysql_query($sql);
        $i      = 0;
        while ($row = mysql_fetch_object($result)) {
            $i++;
            $xmkind_name[$i] = $row->xmkind_name;
        }
        mysql_free_result($result);
        $sql    = "SELECT * FROM `cr_team` WHERE `user_id`='$user_id' AND `team_kind`!=0 AND `team_cid`=$cid ORDER BY `team_id` ASC";
        $result = mysql_query($sql);
     		$sum_team = 0;
        while ($row = mysql_fetch_object($result)) 
        {
            $team_kind[$sum_team] = intval(SqlToHtml($row->team_kind));
            $team_id[$sum_team] = SqlToHtml($row->team_id);
            $team_name[$sum_team] = SqlToHtml($row->team_name);
            $team_coach[$sum_team] = SqlToHtml($row->team_coach);
            $team_phone[$sum_team] = SqlToHtml($row->team_phone);
            $team_xmname[$sum_team] = SqlToHtml($row->team_xmname);
            $sum_team ++;
        }
		require_once("template/".$BM_TEMPLATE."/xiangmu_teamlist.php");
     }
} 
else 
{
    echo "<script language='javascript'>\n";
    echo "alert('这儿什么都没有~~');\n";
    echo "history.go(-1);\n";
    echo "</script>";
    require_once("bm_footer.php");
    exit(0);
}
?>




<?php
require_once("bm_footer.php");
?>
